package com.gobang.controller;

import com.gobang.domain.dto.points.AdminAdjustPointsRequest;
import com.gobang.domain.vo.Result;
import com.gobang.service.PointsService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/api/admin/points")
@PreAuthorize("hasRole('ADMIN')")
@RequiredArgsConstructor
public class AdminPointsController {

    private final PointsService pointsService;

    @PostMapping("/adjust")
    public Result<Void> adjustPoints(@Valid @RequestBody AdminAdjustPointsRequest request) {
        pointsService.adjustPointsForUser(request.getUserId(), request.getDelta(), request.getReason());
        return Result.success("积分调整成功");
    }
}
